package com.example.springbootminiodemo.controller;

import com.example.springbootminiodemo.api.Result;
import com.example.springbootminiodemo.util.MinIOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Auther: LL
 * @Date: 2020/3/30 11:31
 */
@RestController
@RequestMapping("/sys/common")
public class MinioController {
    @Autowired
    MinIOUtils minIOUtils;
    /**
     * 上传图片
     * @param file
     * @return
     */
    @PostMapping("/uploadImage")
    public Result<?> uploadImage(@RequestParam("file") MultipartFile file){
        return minIOUtils.uploadImage(file);

    }

    /**
     * 下载图片
     * @param imageUri
     * @param request
     * @param response
     * @throws Exception
     */
    @GetMapping("/getImageByUri")
    public void   getImageByUri(@RequestParam("imageUri")String imageUri, HttpServletRequest request, HttpServletResponse response) throws Exception {

        response.sendRedirect(minIOUtils.getImageByUri(imageUri));
    }
}
